package com.top145;

public class Solution29 {
    public int divide(int dividend, int divisor) {
        int sign = 1;
        if (dividend < 0 && divisor > 0 || dividend > 0 && divisor < 0) sign = -1;
        int res = 0;
        dividend = dividend < 0 ? -dividend : dividend;
        divisor = divisor < 0 ? -divisor : divisor;
        while (dividend >= divisor) {
            dividend -= divisor;
            res++;
        }
        return sign < 0 ? -res : res;
    }
}
